var { getLoginedUser, setTitle, fnLoading, fnHideLoading, fnSuccess, fnFail } = require('../../utils/index')
import { domainStatic } from '../../utils/env.js';
import { checkLoginAsyc } from '../../utils/util.js';

import _ from '../../utils/underscore.js';
import { get, checkCoupon, fnChoose, lsGetStr, fnUpload, post } from '../../utils/request.js';
var WxParse = require('../wxParse/wxParse.js');

// pages/soft/index.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    other: "",
    image: "",
    desc1: "",
    id: "",
    phone: "",
    butLabel:'申请',
    disabled: false,
    currentTime: 61,
    text: "获取验证码",
    code: "",
    typeId:''
  },
  but: function (e) {
      let that =this;
    if (this.data.butLabel=='加入购物车'){
     return  checkLoginAsyc()
        .then(function () {
          post({
            path: "/order/addShoppingcart",
            data: {
              offerId: that.data.id,
              number: 1,
              skey: lsGetStr('skey')
            }
          })
        })
        .then(function (res) {
          fnSuccess("加入成功....")
        })
        .catch(function(){
          fnFail('加入购物车失败～')
        })
    }
    if (this.data.id == 84) {
      wx.navigateTo({
        url: '../certificate/index?type=' + this.data.id,
      });
    } else {
      wx.navigateTo({
        url: '../certificate/index?type=' + this.data.id,
      });
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    that.setData({
      typeId: options.id
    })
    fnLoading('加载中...')
    // that.setData({
    //   id: options.id,
    // });
    //setTitle(options.id == 85 ? "双软企业申请" : ("高新技术企业"))
    if (options.id == 14194) {
     
      get({
        path: "/offer/get?id=85"
      })
        .then(function (res) {
          res.offer.detail = res.offer.detail.indexOf('%3D') > -1 ? unescape(res.offer.detail) : res.offer.detail;
          console.log(res.offer.detail);
          WxParse.wxParse('detailHtml', 'html', res.offer.detail, that, 5);
          setTitle(res.offer.name);
          // debugger;
          that.setData({
            options: options,
            other: res.offer.name,
            image: res.offer.thumbnail,
            id: res.offer.id,
            desc1: res.offer.desc1,
            price: res.offer.price
          })
          fnHideLoading();
        })
    } else {
     
      get({
        path: "/offer/get?id="+(options.id||87)
      }).then(function (res) {
        res.offer.detail = res.offer.detail.indexOf('%3D') > -1 ? unescape(res.offer.detail) : res.offer.detail;
        WxParse.wxParse('detailHtml', 'html', res.offer.detail, that, 5);
        setTitle(res.offer.name);
        that.setData({
          options: options,
          other: res.offer.name,
          image: res.offer.thumbnail,
          desc1: res.offer.desc1,
          id: res.offer.id,
            price: res.offer.price,
          butLabel: 87 == options.id?'申请':"加入购物车"
        })
        fnHideLoading();
      })
    }
  },
  onShow() {
    checkCoupon();
  },
})